﻿var element, form, $, layer;
layui.use(['element', 'layer', 'form'], function() {
	element = layui.element;
	form = layui.form;
	$ = layui.jquery;
	layer = layui.layer;

	//监听左侧导航点击
	element.on('nav(leftmenu)', function(elem) {
		var url = elem.attr('data-url'); //页面url		
		var id = elem.attr('data-id');
		var title = elem.text(); //菜单名称
		if(title == "首页") {
			element.tabChange('tab', 0);
			return;
		}
		if(url == undefined) {
			return;
		}

		var tabTitleDiv = $('.layui-tab[lay-filter=\'tab\']').children('.layui-tab-title');
		var exist = tabTitleDiv.find('li[lay-id=' + id + ']');
		if(exist.length > 0) {
			//切换到指定索引的卡片
			element.tabChange('tab', id);
		} else {
			element.tabAdd('tab', {
				title: title,
				content: '<iframe src="' + url + '" class="iframe"></iframe>',
				id: id
			});
			//切换到指定索引的卡片
			element.tabChange('tab', id);
		}
	});

	//监听头部导航点击
	element.on('nav(topmenu)', function(elem) {
		var id = elem.attr('data-id');
		if(id == 'updatepwd') {
			var index = layer.open({
				type: 2,
				title: '修改密码',
				shadeClose: true,
				shade: 0.8,
				area: ['80%', '80%'],
				content: 'updatepwd.html', //iframe的url
				success: function(layero, index) {
				},
				end: function() {

				}
			});
		} else if(id == 'exit') {
			layer.confirm('确定要退出吗？', {
				btn: ['确定', '取消'] //按钮
			}, function() {
				sessionStorage.setItem("token", "");
				sessionStorage.setItem("account", "");
				location.href = 'login.html';
			}, function() {

			});
		}
	});
	$("#spanaccount").html(sessionStorage.getItem("account"));
});